package com.ruoyi.a2.service.impl;

import com.ruoyi.a2.domain.A2DynamicsInfo;
import com.ruoyi.a2.domain.A2Pdcc;
import com.ruoyi.a2.service.IA2DynamicsInfoService;
import com.ruoyi.a2.service.IA2StaticInfoService;
import com.ruoyi.a2.service.ITool2aEOfAbnormalValueService;
import com.ruoyi.a2.service.ITool2aSpaceTimeResampleService;
import com.ruoyi.common.enums.CleanStatusEnum;
import com.ruoyi.common.enums.CommonOKNOEnum;
import com.ruoyi.common.utils.Date2Utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;


@Slf4j
@Service
public class Tool2aSpaceTimeResampleImpl implements ITool2aSpaceTimeResampleService
{

    @Autowired
    private IA2DynamicsInfoService a2DynamicsInfoService;

    /**
     *  时空重采样
     *  实现思路如下：
     * （1）循环所有点位，与数据库已有数据进行比对去重，唯一值：MMSI+基准时间+经度+纬度
     *
     * @author :yanlixiong
     * @date :2025-02-17 09:28:54
     */
    @Override
    public List<A2DynamicsInfo> handle(List<A2DynamicsInfo> infoList) {
        for(A2DynamicsInfo info:infoList){
            String baseTimeStr = Date2Utils.formatDate(info.getBaseTime(),Date2Utils.parsePatterns[1]);
            A2DynamicsInfo bean = a2DynamicsInfoService.getByUniqueCombination(info.getMmsiIcao(), baseTimeStr, info.getLon(), info.getLat());
            if(bean!=null){
                info.setCleanStatus(CleanStatusEnum.DATA_3.getCode());
            }
            info.setHandleCleanStatus3(CommonOKNOEnum.OK.getCode());
            a2DynamicsInfoService.updateA2DynamicsInfo(info);
        }
        return infoList;
    }
}
